home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / emulator / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / src / UI / tools.tk < prev   
Text File  |  1995-07-26  |  8KB  |  207 lines

  1. ###############################################################################
  2. # $Id: tools.tk,v 1.1 1994/02/18 20:29:45 bmott Exp $
  3. ###############################################################################
  4. # tools.tk - Routines to implement several useful routines
  5. #
  6. # Copyright 1993 
  7. # Bradford W. Mott
  8. # November 19,1993
  9. ###############################################################################
  10. # $Log: tools.tk,v $
  11. # Revision 1.1  1994/02/18  20:29:45  bmott
  12. # Initial revision
  13. #
  14. ###############################################################################
  15.  
  16.  
  17. ###############################################################################
  18. # Dummy do nothing procedure
  19. ###############################################################################
  20. proc NOP {} {}
  21.  
  22. ###############################################################################
  23. # Simple "child" dialog to get a value from the user 
  24. ###############################################################################
  25. proc ChildEntryDialog {parent_window label regular_expression} {
  26.   global ReturnValue
  27.   global EntryDialogRegExp
  28.   global EntryDialogParent
  29.  
  30.   set EntryDialogRegExp $regular_expression
  31.   set EntryDialogParent $parent_window
  32.  
  33.   ## Just in case destroy the window
  34.   catch {destroy $EntryDialogParent.entryDialog}
  35.  
  36.   ## Create the dialog frame
  37.   frame $EntryDialogParent.entryDialog -relief raised -borderwidth 3
  38.  
  39.   ## Create the dialog label
  40.   message $EntryDialogParent.entryDialog.message -text $label \
  41.       -width 3i -justify left
  42.  
  43.   ## Create Entry field
  44.   entry $EntryDialogParent.entryDialog.entry -width 20 -relief sunken
  45.   $EntryDialogParent.entryDialog.entry icursor 0
  46.   bind $EntryDialogParent.entryDialog.entry <Return> {
  47.         set ReturnValue [$EntryDialogParent.entryDialog.entry get]
  48.         if {[regexp $EntryDialogRegExp $ReturnValue]} {
  49.           destroy $EntryDialogParent.entryDialog 
  50.         } else {
  51.           ChildAlertDialog $EntryDialogParent \
  52.               {The value you entered is not valid!!!}
  53.           grab set $EntryDialogParent.entryDialog
  54.         }
  55.       }
  56.  
  57.   ## Create the OK and Cancel button field
  58.   frame $parent_window.entryDialog.buttons
  59.     button $EntryDialogParent.entryDialog.buttons.ok -text "Okay" \
  60.         -command { set ReturnValue [$EntryDialogParent.entryDialog.entry get]
  61.                    if {[regexp $EntryDialogRegExp $ReturnValue]} {
  62.                      destroy $EntryDialogParent.entryDialog 
  63.                    } else {
  64.                      ChildAlertDialog $EntryDialogParent \
  65.                          "The value you entered is not valid!!!"
  66.                      grab set $EntryDialogParent.entryDialog
  67.                    }
  68.                  }
  69.     button $EntryDialogParent.entryDialog.buttons.cancel -text "Cancel" \
  70.         -command {set ReturnValue ""; destroy $EntryDialogParent.entryDialog}
  71.     pack $EntryDialogParent.entryDialog.buttons.ok -side left -expand 1 \
  72.         -fill x -padx 4
  73.     pack $EntryDialogParent.entryDialog.buttons.cancel -side right -expand 1 \
  74.         -fill x -padx 4
  75.  
  76.   pack $EntryDialogParent.entryDialog.message -side top -fill x -pady 4 -padx 4
  77.   pack $EntryDialogParent.entryDialog.entry -side top -fill x -pady 4 -padx 4
  78.   pack $EntryDialogParent.entryDialog.buttons -side top -fill x -pady 4
  79.  
  80.   place $EntryDialogParent.entryDialog -relx 0.5 -rely 0.5 -anchor center
  81.  
  82.   ## Make this a modal dialog
  83.   tkwait visibility $EntryDialogParent.entryDialog
  84.   focus $EntryDialogParent.entryDialog.entry
  85.   grab set $EntryDialogParent.entryDialog
  86.   tkwait window $EntryDialogParent.entryDialog
  87.  
  88.   return $ReturnValue
  89. }
  90.  
  91. ###############################################################################
  92. # Bring up a "child" alert dialog with the given message
  93. ###############################################################################
  94. proc ChildAlertDialog {parent_window the_message} {
  95.   global AlertDialogParent
  96.  
  97.   set AlertDialogParent $parent_window
  98.  
  99.   ## Just in case destroy the window
  100.   catch {destroy $AlertDialogParent.alertDialog}
  101.  
  102.   frame $AlertDialogParent.alertDialog -relief raised -borderwidth 3
  103.  
  104.   label $AlertDialogParent.alertDialog.label -bitmap warning -relief ridge \
  105.       -padx 8 -pady 8 -borderwidth 3
  106.   message $AlertDialogParent.alertDialog.message -text $the_message \
  107.       -width 3i -justify left
  108.   button $AlertDialogParent.alertDialog.button -text "Okay" \
  109.       -command {destroy $AlertDialogParent.alertDialog}
  110.  
  111.   pack $AlertDialogParent.alertDialog.label -side left -padx 8 -pady 8
  112.   pack $AlertDialogParent.alertDialog.message -side top -padx 4 -pady 8
  113.   pack $AlertDialogParent.alertDialog.button -side top -fill x -padx 4 -pady 4
  114.  
  115.   place $AlertDialogParent.alertDialog -relx 0.5 -rely 0.5 -anchor center
  116.  
  117.   ## Make this a modal dialog
  118.   tkwait visibility $AlertDialogParent.alertDialog
  119.   grab set $AlertDialogParent.alertDialog
  120.   tkwait window $AlertDialogParent.alertDialog 
  121. }
  122.  
  123.  
  124. ###############################################################################
  125. # Simple "toplevel" dialog to get a value from the user
  126. ###############################################################################
  127. proc EntryDialog {label window_title regular_expression} {
  128.   global ReturnValue
  129.   global EntryDialogRegExp
  130.  
  131.   set EntryDialogRegExp $regular_expression
  132.  
  133.   ## Just in case destroy the window
  134.   catch {destroy .entryDialog}
  135.  
  136.   ## Create a toplevel window
  137.   toplevel .entryDialog
  138.   wm title .entryDialog $window_title
  139.   wm iconname .entryDialog $window_title
  140.  
  141.   ## Create the dialog label
  142.   message .entryDialog.message -text $label -width 3i -justify left
  143.  
  144.   ## Create Entry field
  145.   frame .entryDialog.value -relief ridge -borderwidth 2 
  146.     entry .entryDialog.value.entry -width 10
  147.     bind .entryDialog.value.entry <Return> {
  148.           set ReturnValue [.entryDialog.value.entry get]
  149.           if {[regexp $EntryDialogRegExp $ReturnValue]} {
  150.             destroy .entryDialog 
  151.           } else {AlertDialog {That is not a valid value!!!}}
  152.         }
  153.     pack .entryDialog.value.entry -side left -fill x -expand 1 -padx 4
  154.  
  155.   ## Create the OK and Cancel button field
  156.   frame .entryDialog.buttons
  157.     button .entryDialog.buttons.ok -text "Okay" \
  158.         -command { set ReturnValue [.entryDialog.value.entry get]
  159.                    if {[regexp $EntryDialogRegExp $ReturnValue]} {
  160.                      destroy .entryDialog 
  161.                    } else {AlertDialog {That is not a valid value!!!}}
  162.                  }
  163.     button .entryDialog.buttons.cancel -text "Cancel" \
  164.         -command {set ReturnValue ""; destroy .entryDialog}
  165.     pack .entryDialog.buttons.ok -side left -expand 1 -fill x -padx 4
  166.     pack .entryDialog.buttons.cancel -side right -expand 1 -fill x -padx 4
  167.  
  168.   pack .entryDialog.message -side top -fill x -pady 4 -padx 4
  169.   pack .entryDialog.value -side top -fill x -pady 4 -padx 4
  170.   pack .entryDialog.buttons -side top -fill x -pady 4
  171.  
  172.   ## Make this a modal dialog
  173.   tkwait visibility .entryDialog
  174.   grab set .entryDialog
  175.   tkwait window .entryDialog
  176.  
  177.   return $ReturnValue
  178. }
  179.  
  180. ###############################################################################
  181. # Bring up a "toplevel" alert dialog with the given message
  182. ###############################################################################
  183. proc AlertDialog {the_message} {
  184.  
  185.   ## Just in case destroy the window
  186.   catch {destroy .alertDialog}
  187.  
  188.   toplevel .alertDialog
  189.   wm title .alertDialog "Alert Dialog"
  190.   wm iconname .alertDialog "Alert Dialog"
  191.  
  192.   label .alertDialog.label -bitmap warning -relief ridge -padx 8 -pady 8 \
  193.       -borderwidth 3
  194.   message .alertDialog.message -text $the_message -width 2.5i -justify left
  195.   button .alertDialog.button -text "Okay" -command {destroy .alertDialog}
  196.  
  197.   pack .alertDialog.label -side left -padx 8 -pady 8
  198.   pack .alertDialog.message -side top -padx 4 -pady 4
  199.   pack .alertDialog.button -side top -fill x -padx 4 -pady 4
  200.  
  201.   ## Make this a modal dialog
  202.   tkwait visibility .alertDialog
  203.   grab set .alertDialog
  204.   tkwait window .alertDialog 
  205. }
  206.  
  207.